<template>
  <div class="wrap">
    <pro-table
      ref="proTableInst"
      :tableTitle="title + '的盘点列表'"
      :columns="columns"
      :request="fetchInventoryDetailsPage"
    >
      <template #operation>
        <n-space>
          <n-popover
            trigger="hover"
            :show-arrow="false"
            placement="top"
            content-style="display: flex"
            display-directive="show"
            v-if="type !== 'detail'"
          >
            <template #trigger>
              <n-popconfirm
                placement="bottom"
                :on-positive-click="fetchInventoryAll"
              >
                您确定要整单完成？
                <template #trigger>
                  <n-button type="success">整单完成</n-button>
                </template>
              </n-popconfirm>
            </template>
            整单完成会把所有未盘点的资产状态设置为已盘点
          </n-popover>
        </n-space>
      </template>
    </pro-table>
  </div>
</template>

<script lang="ts" setup name="Inventory">
  import { ProTableInst } from '@/components/pro-table/type'
  import { useInventoryApi, useInventoryProTable } from './hooks'
  import { useUser } from '@/store/modules/user'

  const proTableInst = ref<ProTableInst | null>(null)

  const router = useEncryptRouter()
  const { type, code, title } = router.getQuery()

  const { userInfo } = storeToRefs(useUser())
  // const { memberLoading, memberOptions } = useGetOrgMemberList()

  const {
    confirmLoading,
    fetchInventoryDetailsPage,
    fetchInventory,
    fetchInventoryAll
  } = useInventoryApi({
    title,
    code,
    userInfo,
    proTableInst
  })
  const { columns } = useInventoryProTable({
    type,
    fetchInventory
  })
</script>

<style lang="less" scoped></style>
